﻿@model GaclibWebPage.Models.GettingStartPageModel

@{
    ViewBag.Title = "GacLib - Getting Started - Step 6";
}
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shCore.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushCpp.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushXml.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushPlain.js")"></script>
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shCore.css")" />
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shThemeRDark.css")" />
<tr>
    <td align="left" valign="top" colspan="6">
        <h1>Step 6. @Model.TutorialTitles[5]</h1>
        <p>The latest version of the GacGen.exe provides the precompiling resource feature. You can modify the XML file and add the "PrecompiledOutput", "PrecompiledBinary" and "PrecompiledCompressed" properties.</p>
        <div class="CppCode">
            <pre class="brush: xml; gutter: false;">
&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Resource&gt;
  &lt;Folder name="GacGenConfig"&gt;
    &lt;Text name="Include"&gt;..\..\..\Public\Source\GacUIReflection.h&lt;/Text&gt;
    &lt;Text name="Name"&gt;HelloWorld&lt;/Text&gt;
    &lt;Text name="Prefix"&gt;&lt;/Text&gt;
    &lt;Text name="PrecompiledOutput"&gt;Precompiled.xml&lt;/Text&gt;
    &lt;Text name="PrecompiledBinary"&gt;Precompiled.bin&lt;/Text&gt;
    &lt;Text name="PrecompiledCompressed"&gt;Precompiled.compressed&lt;/Text&gt;
  &lt;/Folder&gt;
  &lt;Folder name="MainWindow"&gt;
    &lt;Instance name="MainWindowResource"&gt;
      &lt;Instance ref.Class="helloworld::MainWindow"&gt;
        &lt;Window Text="Hello, world!" ClientSize="x:640 y:480"&gt;
          &lt;Label Text="Welcome to GacUI Library!"&gt;
            &lt;att.Font&gt;fontFamily:{Segoe UI} size:40 antialias:true&lt;/att.Font&gt;
          &lt;/Label&gt;
        &lt;/Window&gt;
      &lt;/Instance&gt;
    &lt;/Instance&gt;
  &lt;/Folder&gt;
&lt;/Resource&gt;
            </pre>
        </div>
        <p>You don't have to add all 3 kinds of precompiled resource output. You can choose one of them as you like:</p>
        <ul>
            <li><b>PrecompiledOutput</b>: The output is a precompiled xml file. This kind of precompiled resource is always for debugging. When you use the MVVM pattern with data binding to build your UI, the precompiled XML file contains a lot of binary data, which are the result of all those compiled script code, and then becomes very big. A big xml file causes a lot of time to load.</li>
            <li><b>PrecompiledBinary</b>: The output is a precompiled binary file. This is the recommended kind of precompiled resource.</li>
            <li><b>PrecompiledCompressed</b>: The output is a precompiled compressed binary file. You can put those files as resources in your exe file, and decompress them into the disk when your program is running at the first time.</li>
        </ul>
        <h2>Loading a precompiled xml resource</h2>
        <div class="cpp">
            <pre class="brush: cpp; gutter: false;">
void GuiMain()
{
    List&lt;WString&gt; errors;
    auto resource = GuiResource::LoadFromXml(L"Precompiled.xml", errors);
	GetInstanceLoaderManager()-&gt;SetResource(L"Resource", resource);
}
            </pre>
        </div>
        <h2>Loading a precompiled binary resource</h2>
        <div class="cpp">
            <pre class="brush: cpp; gutter: false;">
void GuiMain()
{
    List&lt;WString&gt; errors;
    FileStream fileStream(L"Precompiled.bin", FileStream::ReadOnly);
    auto resource = GuiResource::LoadPrecompiledBinary(fileStream, errors);
	GetInstanceLoaderManager()-&gt;SetResource(L"Resource", resource);
}
            </pre>
        </div>
        <h2>Loading a precompiled compressed binary resource</h2>
        <div class="cpp">
            <pre class="brush: cpp; gutter: false;">
void GuiMain()
{
    List&lt;WString&gt; errors;
    FileStream fileStream(L"Precompiled.bin", FileStream::ReadOnly);
    LzwEncoder encoder;
    EncoderStream encoderStream(fileStream, encoder);
    auto resource = GuiResource::LoadPrecompiledBinary(encoderStream, errors);
	GetInstanceLoaderManager()-&gt;SetResource(L"Resource", resource);
}
            </pre>
        </div>
    </td>
</tr>
<script type="text/javascript">
    SyntaxHighlighter.all()
</script>